package com.mdx.zhizhao.controller;

import com.mdx.zhizhao.domain.Job;
import com.mdx.zhizhao.domain.Response;
import com.mdx.zhizhao.domain.Seeker;
import com.mdx.zhizhao.service.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/job" ,produces = {MediaType.APPLICATION_JSON_VALUE,MediaType.APPLICATION_XML_VALUE})
public class JobController {
    @Autowired
    private JobService jobService;
    @PostMapping("insertJob")
    public Response<Job> insertJob(@RequestBody Job job){
        int size=(jobService.selectJobByEnterpriseId(job.getEnterpriseid())).size();
        String s= String.valueOf(size+1);
        job.setJobid(job.getEnterpriseid()+s);
        jobService.insertJob(job);
        Response<Job> response = new Response<>();
        response.s(job, "成功");
        return response;
    }
    @PostMapping("/updateJob")
    public Response<Job> updateSeeker(@RequestBody Job job) {
        jobService.updateJob(job);
        Response<Job> response = new Response<>();
        response.s(job, "成功");
        return response;
    }
    @PostMapping("/selectJob")
    public Response<Job> selectJob(@RequestBody Job job) {
        Response<Job> response = new Response<>();
        Job job1=jobService.selectJob(job.getJobid());
        response.s(job1,"成功");
        return response;
    }
    @PostMapping("/selectJobByEnterpriseId")
    public List<Job> selectJobByEnterpriseId(@RequestBody Job job) {
        return jobService.selectJobByEnterpriseId(job.getEnterpriseid());
    }
    @PostMapping("/deleteJob")
    public Response<Job> deleteJob(@RequestBody Job job) {
        jobService.deleteJob(job.getJobid());
        Response<Job> response = new Response<>();
        response.s(job,"成功");
        return response;
    }
}
